﻿namespace NCql.Parser
{
    public abstract class ContextIdentifier
    {
        protected string fullName;

        public string FullName
        {
            get { return fullName; }
            set { fullName = value; }
        }

        public string BaseName
        {
            get
            {
                if (fullName == null)
                    return string.Empty;

                if (!fullName.Contains("."))
                    return fullName;

                return fullName.Substring(1 + fullName.IndexOf('.'));
            }
        }

        public string Prefix
        {
            get
            {
                if (fullName == null)
                    return string.Empty;

                if (!fullName.Contains("."))
                    return string.Empty;

                return fullName.Substring(0, fullName.IndexOf("."));
            }
        }

        public override string ToString()
        {
            if (string.IsNullOrEmpty(fullName))
                return "(Undefined)";

            return fullName;
        }
    }
}